/**
 *******************************************************************************************************************************************
 * @file        dev_lcd.c
 * @brief       LCD 驱动显示
 * @details     /
 * @since       Change Logs:
 * Date         Author       Notes
 * 2022-12-08   lzh          the first version
 * @remark      /
 *******************************************************************************************************************************************
 * @attention
 *
 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
 * REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
 * FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
 * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
 * -ECTION WITH THEIR PRODUCTS.
 *
 * @copyright   2012 Synwit Technology
 *******************************************************************************************************************************************
 */
#include "dev_lcd.h"
#include "dev_systick.h"
#include "version.h"

/*******************************************************************************************************************************************
 * Private Define
 *******************************************************************************************************************************************/
#if (SWM34S_LCM_PCBV == SWM34SCE_PIN48_A2)
#define LCD_GPIO_RST                GPIOM
#define LCD_PIN_RST                 PIN1

#define LCD_GPIO_BL                 GPIOA
#define LCD_PIN_BL                  PIN8

//#define LCD_PORT_BL               PORTM   // A8 不支持硬件 PWM, 需要软件模拟实现
//#define LCD_PORT_FUNC_BL          PORTM_PIN1_PWM0A
//#define LCD_PWMN_BL                   PWM0
//#define LCD_PWMN_MSK_BL               PWM0_MSK

#elif (SWM34S_LCM_PCBV == SWM34SRE_PIN64_A001)
#define LCD_GPIO_RST                GPIOD
#define LCD_PIN_RST                 PIN1

#define LCD_GPIO_BL                 GPIOD
#define LCD_PIN_BL                  PIN9

#define LCD_PORT_BL                 PORTD
#define LCD_PORT_FUNC_BL            PORTD_PIN9_PWM1B
#define LCD_PWMN_BL                 PWM1
#define LCD_PWMN_MSK_BL             PWM1_MSK

#else /* SWM34SVET6_Pin100 */
#define LCD_GPIO_RST                GPIOD
#define LCD_PIN_RST                 PIN1

#define LCD_GPIO_BL                 GPIOD
#define LCD_PIN_BL                  PIN9

#define LCD_PORT_BL                 PORTD
#define LCD_PORT_FUNC_BL            PORTD_PIN9_PWM1B
#define LCD_PWMN_BL                 PWM1
#define LCD_PWMN_MSK_BL             PWM1_MSK

#endif

/*******************************************************************************************************************************************
 * Private Prototype
 *******************************************************************************************************************************************/
static void lcd_set_parameter(LCD_InitStructure *lcd_parameter);

static void RGB565__SWM34SCE_PIN48_A2(void);
static void RGB565__SWM34SRE_PIN64_A001(void);
static void RGB565__SWM34SVE_PIN100_A001(void);
static void RGB888__SWM34SVE_PIN100_A001(void);
static void RGB565__SWM34SVE_PIN100_A002(void);
static void RGB888__SWM34SVE_PIN100_A002(void);

/*******************************************************************************************************************************************
 * Public Function
 *******************************************************************************************************************************************/
/**
 * @brief   初始化 LCD 模块, 并根据实际分辨率进行配置
 * @note    若用户选择了自定义的屏, 仅 LCD 屏参适配项 与 初始化时序 需要根据不同的屏进行适配调整
 */
void lcd_init(void)
{
    /* 复位时序请参考屏幕厂家提供的规格书描述进行 */
   // GPIO_Init(LCD_GPIO_RST, LCD_PIN_RST, 1, 1, 0, 0);
   // GPIO_AtomicClrBit(LCD_GPIO_RST, LCD_PIN_RST);
    systick_delay_ms(1);
    GPIO_AtomicSetBit(LCD_GPIO_RST, LCD_PIN_RST);
    /* 注意:若屏幕需要进行特定时序/参数的初始化（如SPI）,则应在 复位后~LCD_Start前 之间进行 */
    LCD_InitStructure LCD_initStruct;
    /* LCD 屏参适配（以及部分屏幕需要 SPI 初始化也在此函数内进行） */
    lcd_set_parameter(&LCD_initStruct);
    /* 分辨率及色彩 */
    LCD_initStruct.HnPixel = LCD_HDOT;
    LCD_initStruct.VnPixel = LCD_VDOT;
    LCD_initStruct.Format = (LCD_FMT == LCD_ARGB888) ? LCD_FMT_RGB888 : LCD_FMT_RGB565;
    /* 背景色 */
    LCD_initStruct.Background = (LCD_initStruct.Format == LCD_FMT_RGB888) ? 0xFFFFFF : 0xFFFF;
    /* 图层 1 被 lvgl 使用, 此处仅做初始化临时值, 在 disp_flush() 会切换至 lcdbuf_gui/show 帧缓冲区域 */
    LCD_initStruct.DataSource = (uint32_t)SDRAMM_BASE;
    /* 0-失能传输完成中断, 刷完一帧自动开始刷新下一帧(用户无须参与)
     * 1-使能传输完成中断, 须在中断内软件启动刷新下一帧(开启后可提供接口以测试实际帧率)
     */
    LCD_initStruct.IntEOTEn = 0;
    /* LCD 端口适配 */
    lcd_port_init();
    /* LCD 模块初始化 */
    LCD_Init(LCD, &LCD_initStruct);
    /* 背光 */
    lcd_set_bg_light(100);
}

/**
 * @brief   初始化 LCD 驱动端口
 */
void lcd_port_init(void)
{
    /* LCD 硬件端口适配不同版本的 Demo 板 */
    #if (LCD_FMT == LCD_RGB565)
    #if (SWM34S_LCM_PCBV == SWM34SCE_PIN48_A2)
    RGB565__SWM34SCE_PIN48_A2();
    #elif (SWM34S_LCM_PCBV == SWM34SRE_PIN64_A001)
    RGB565__SWM34SRE_PIN64_A001();
    #elif (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A001)
    RGB565__SWM34SVE_PIN100_A001();
    #elif (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A002)
    RGB565__SWM34SVE_PIN100_A002();
    #endif
    #elif (LCD_FMT == LCD_ARGB888)
    #if (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A001)
    RGB888__SWM34SVE_PIN100_A001();
    #elif (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A002)
    RGB888__SWM34SVE_PIN100_A002();
    #endif
    #endif
}

/**
 * @brief   LCD 背光亮度调节
 * @param   百分比亮度(0:暗       0~100:自定义亮度     100:亮)
 * @retval  /
 * @note    百分比单位亮度可自定义
 */
void lcd_set_bg_light(uint8_t percentage)
{
    #if (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A001)
    /* 背光选通使能 <<仅针对 SWM34SVE_PIN100_A001 七寸屏背光电路(VGH/VGL)有效>> */
#define LCD_GPIO_BKL_EN         GPIOA
#define LCD_PIN_BKL_EN          PIN1
    /* 选通 AP3012KTR-E1 芯片 */
    GPIO_Init(LCD_GPIO_BKL_EN, LCD_PIN_BKL_EN, 1, 1, 0, 0);
    GPIO_AtomicSetBit(LCD_GPIO_BKL_EN, LCD_PIN_BKL_EN);
    #endif
    /* 背光控制可选 IO 直驱 / PWN 调光 */
    if (percentage >= 100)
    {
        GPIO_Init(LCD_GPIO_BL, LCD_PIN_BL, 1, 1, 0, 0);
        GPIO_AtomicSetBit(LCD_GPIO_BL, LCD_PIN_BL); /* 点亮背光 */
    }
    else if (percentage == 0)
    {
        GPIO_Init(LCD_GPIO_BL, LCD_PIN_BL, 1, 1, 0, 0);
        GPIO_AtomicClrBit(LCD_GPIO_BL, LCD_PIN_BL); /* 熄灭背光 */
    }
    else /* (0 ~ 100) PWM 调节背光 */
    {
        #if (SWM34S_LCM_PCBV != SWM34SCE_PIN48_A2)
        /* 如果遇到该端口无法复用成 PWM 功能, 则只能用 Timer 软件进行 IO 翻转, 这将十分消耗软件资源
         * 尽量选用可配置为 PWM Out 的端口作背光
         */
        PORT_Init(LCD_PORT_BL, LCD_PIN_BL, LCD_PORT_FUNC_BL, 0);
        PWM_InitStructure PWM_initStruct;
        PWM_initStruct.Mode = PWM_CENTER_ALIGNED;
        PWM_initStruct.Clkdiv = 4;     // F_PWM = 140M / 4 = 35M
        PWM_initStruct.Period = 10000; // 35M/10000 = 3500Hz，中心对称模式下频率降低到1750Hz
        //2500;
        PWM_initStruct.HdutyA = (PWM_initStruct.Period) / 100 * percentage;
        PWM_initStruct.DeadzoneA = 50;//死区时长
        PWM_initStruct.IdleLevelA = 0;
        PWM_initStruct.IdleLevelAN = 0;
        PWM_initStruct.OutputInvA = 0;
        PWM_initStruct.OutputInvAN = 0;
        //5000; // 5000/10000 = 50%
        PWM_initStruct.HdutyB = (PWM_initStruct.Period) / 100 * percentage;
        PWM_initStruct.DeadzoneB = 50;//死区时长
        PWM_initStruct.IdleLevelB = 0;
        PWM_initStruct.IdleLevelBN = 0;
        PWM_initStruct.OutputInvB = 0;
        PWM_initStruct.OutputInvBN = 0;
        PWM_initStruct.UpOvfIE = 0;
        PWM_initStruct.DownOvfIE = 0;
        PWM_initStruct.UpCmpAIE = 0;
        PWM_initStruct.DownCmpAIE = 0;
        PWM_initStruct.UpCmpBIE = 0;
        PWM_initStruct.DownCmpBIE = 0;
        PWM_Init(LCD_PWMN_BL, &PWM_initStruct);
        PWM_Start(LCD_PWMN_MSK_BL);
        //PWM_SetHDuty2
        //PWM_SetHDuty(LCD_PWMN_MSK_BL, chn, PWM_GetPeriod(LCD_PWMN_MSK_BL) / 100 * percentage);
        //PWM_Restart(LCD_PWMN_MSK_BL);
        #endif
    }
}

/**
 * @brief   LCD ISR Callback
 */
void isr_lcd_transfer_done(void)
{
    LCD_INTClr(LCD);
    LCD_Start(LCD);
}

/*******************************************************************************************************************************************
 * Private Function
 *******************************************************************************************************************************************/
static void lcd_set_parameter(LCD_InitStructure *lcd_parameter)
{
    LCD_InitStructure LCD_initStruct;
    /*  一些屏参的计算参考示例, 实际请依据屏幕规格书为准
        HSYNC Blanking = 160 DCLK = HS Pulse Width + HS Back Porch
        HS Pulse Width = 1 ~ 140 DCLK
        1 Horizontal Line = 1344 DCLK   (1200 ~ 1400)

        VSYNC Blanking = 23 H     = VS Pulse Width + VS Back Porch
        VS Pulse Width = 1 ~ 20 H
        VSYNC period time = 635 H       (624 ~ 750)
    */
    #if (LCD_TYPE == JLT4303A)
    /* [480*272] 晶力泰 4.3 寸屏 + CTP */
    LCD_initStruct.ClkDiv = 9;
    LCD_initStruct.Hfp = 8;
    LCD_initStruct.Hbp = 40;
    LCD_initStruct.Vfp = 8;
    LCD_initStruct.Vbp = 12;
    LCD_initStruct.HsyncWidth = 8;
    LCD_initStruct.VsyncWidth = 8;
    LCD_initStruct.SampleEdge = LCD_SAMPLE_FALL;
	
//	
//	 LCD_initStruct.ClkDiv = 10;
//    LCD_initStruct.Hfp = 5;
//    LCD_initStruct.Hbp = 40;
//    LCD_initStruct.Vfp = 8;
//    LCD_initStruct.Vbp = 8;
//    LCD_initStruct.HsyncWidth = 5;
//    LCD_initStruct.VsyncWidth = 5;
//    LCD_initStruct.SampleEdge = LCD_SAMPLE_FALL;
    #elif (LCD_TYPE == JLT35002A_V2)
    /* [480*320 / 320*480] 晶力泰 3.5 寸屏 + CTP (JLT35002A 仅 V2 版本支持 RGB 模式驱动, 请勿买错 V3 版本) */
#include "LCD_JLT35002A.h"
    lcd_spi_init_JLT35002A();
    #if (SWM34S_LCM_PCBV != SWM34SCE_PIN48_A2)
#error "for LCD_JLT35002A, SWM34S_LCM_PCBV must select SWM34SCE_PIN48_A2!"
    #endif
    LCD_initStruct.ClkDiv = 10;
    LCD_initStruct.Hfp = 4;
    LCD_initStruct.Hbp = 4;
    LCD_initStruct.Vfp = 2;
    LCD_initStruct.Vbp = 1;
    LCD_initStruct.HsyncWidth = 2;
    LCD_initStruct.VsyncWidth = 5;
    LCD_initStruct.SampleEdge = LCD_SAMPLE_FALL;
    #elif (LCD_TYPE == TL040WVS03)
    /* [480*480] 冠显光电 4.0 寸方屏 + CTP */
#include "LCD_TL040WVS03.h"
    lcd_spi_init_TL040WVS03();
    LCD_initStruct.ClkDiv = 6;
    LCD_initStruct.Hfp = 10;
    LCD_initStruct.Hbp = 30;
    LCD_initStruct.Vfp = 20;
    LCD_initStruct.Vbp = 20;
    LCD_initStruct.HsyncWidth = 5;
    LCD_initStruct.VsyncWidth = 5;
    LCD_initStruct.SampleEdge = LCD_SAMPLE_RISE; /* 注意采样沿 */
    #elif (LCD_TYPE == TL021WVC02)
    /* [480*480] 冠显光电 2.1 寸圆屏 + CTP */
#include "LCD_TL021WVC02.h"
    lcd_spi_init_TL021WVC02();
    LCD_initStruct.ClkDiv = 6;
    LCD_initStruct.Hfp = 10;
    LCD_initStruct.Hbp = 30;
    LCD_initStruct.Vfp = 20;
    LCD_initStruct.Vbp = 20;
    LCD_initStruct.HsyncWidth = 5;
    LCD_initStruct.VsyncWidth = 5;
    LCD_initStruct.SampleEdge = LCD_SAMPLE_RISE; /* 注意采样沿 */
    #elif (LCD_TYPE == JLT4305A)
    /* [800*480] 晶力泰 4.3 寸屏 + CTP */
    LCD_initStruct.ClkDiv = 4;
    LCD_initStruct.Hfp = 64;
    LCD_initStruct.Hbp = 46;
    LCD_initStruct.Vfp = 22;
    LCD_initStruct.Vbp = 45;
    LCD_initStruct.HsyncWidth = 5;
    LCD_initStruct.VsyncWidth = 5;
    LCD_initStruct.SampleEdge = LCD_SAMPLE_FALL;
    #elif (LCD_TYPE == ATK_MD0700R)
    /* [800*480] 正点原子 7 寸屏 + CTP */
    /* STM32F429-LTCD ( TP-FT5206 驱动平替 TP-CST340 )
    lcdltdc.hsw=1;   //水平同步宽度
    lcdltdc.vsw=1;   //垂直同步宽度
    lcdltdc.hbp=46;  //水平后廊
    lcdltdc.vbp=23;  //垂直后廊
    lcdltdc.hfp=210; //水平前廊
    lcdltdc.vfp=22;  //垂直前廊
    */
    /* 这款屏应用ARGB888的效果不理想 */
    LCD_initStruct.ClkDiv = 5;//4;
    LCD_initStruct.Hfp = 64;
    LCD_initStruct.Hbp = 46;
    LCD_initStruct.Vfp = 22;
    LCD_initStruct.Vbp = 23;
    LCD_initStruct.HsyncWidth = 5;
    LCD_initStruct.VsyncWidth = 5;
    LCD_initStruct.SampleEdge = LCD_SAMPLE_FALL;
    #elif (LCD_TYPE == WKS70170)
    /* [1024*600] 慧勤光电 7 寸屏 + CTP */
    LCD_initStruct.ClkDiv = 3; // type: 51.2 MHz
    LCD_initStruct.Hfp = 64;   // 16~216 type:160
    LCD_initStruct.Hbp = 140;
    LCD_initStruct.Vfp = 12;    // 1~127 type:12
    LCD_initStruct.Vbp = 20;
    LCD_initStruct.HsyncWidth = 20;
    LCD_initStruct.VsyncWidth = 3;
    LCD_initStruct.SampleEdge = LCD_SAMPLE_FALL;
    #elif (LCD_TYPE == RS_7_V1_3)
    /* [1024*600] 玫瑰科技 7 寸屏 + CTP */
    LCD_initStruct.ClkDiv = 3;      // type: 51.2 MHz
    LCD_initStruct.Hfp = 64;        // 64;//max:64
    LCD_initStruct.Hbp = 160;       // 140;//max:256
    LCD_initStruct.Vfp = 12;        // 12;//max:64
    LCD_initStruct.Vbp = 23;        // 12;//max:256
    LCD_initStruct.HsyncWidth = 20; // max:256
    LCD_initStruct.VsyncWidth = 3;  // max:256
    LCD_initStruct.SampleEdge = LCD_SAMPLE_FALL;
    #else
#error "You must provide your customized LCD Driver!"
    #endif
    lcd_parameter->ClkDiv = LCD_initStruct.ClkDiv;
    lcd_parameter->Hfp = LCD_initStruct.Hfp;
    lcd_parameter->Hbp = LCD_initStruct.Hbp;
    lcd_parameter->Vfp = LCD_initStruct.Vfp;
    lcd_parameter->Vbp = LCD_initStruct.Vbp;
    lcd_parameter->HsyncWidth = LCD_initStruct.HsyncWidth;
    lcd_parameter->VsyncWidth = LCD_initStruct.VsyncWidth;
    lcd_parameter->SampleEdge = LCD_initStruct.SampleEdge;
}

static void RGB565__SWM34SCE_PIN48_A2(void)
{
    /* R- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTN, PIN5,  PORTN_PIN5_LCD_R3,  0);
    PORT_Init(PORTD, PIN0,  PORTD_PIN0_LCD_R4, 0);
    PORT_Init(PORTD, PIN1,  PORTD_PIN1_LCD_R5, 0);
    PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
    PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
    /* G- 6 bit : [ 2 ~ 7 ] */
    PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
    PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
    PORT_Init(PORTC, PIN0,  PORTC_PIN0_LCD_G4,  0);
    PORT_Init(PORTC, PIN1,  PORTC_PIN1_LCD_G5,  0);
    PORT_Init(PORTC, PIN2,  PORTC_PIN2_LCD_G6,  0);
    PORT_Init(PORTC, PIN3,  PORTC_PIN3_LCD_G7,  0);
    /* B- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTA, PIN1,  PORTA_PIN1_LCD_B3, 0);
    PORT_Init(PORTA, PIN2,  PORTA_PIN2_LCD_B4,  0);
    PORT_Init(PORTA, PIN9,  PORTA_PIN9_LCD_B5,  0);
    PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
    PORT_Init(PORTA, PIN0,  PORTA_PIN0_LCD_B7, 0);
    /* CLK / VS / HS / DE */
    PORT_Init(PORTN, PIN0,  PORTN_PIN0_LCD_DCLK,  0);
    PORT_Init(PORTB, PIN2,  PORTB_PIN2_LCD_VSYNC, 0);
    PORT_Init(PORTM, PIN8,  PORTM_PIN8_LCD_HSYNC, 0);
    PORT_Init(PORTM, PIN11, PORTM_PIN11_LCD_DEN,  0);
}

static void RGB565__SWM34SRE_PIN64_A001(void)
{
    /* R- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
    PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
    PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
    PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
    PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
    /* G- 6 bit : [ 2 ~ 7 ] */
    PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
    PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
    PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
    PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
    PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
    PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
    /* B- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
    PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
    PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
    PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
    PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);
    /* CLK / VS / HS / DE */
    PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
    PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);
    PORT_Init(PORTB, PIN3, PORTB_PIN3_LCD_HSYNC, 0);
    PORT_Init(PORTB, PIN4, PORTB_PIN4_LCD_DEN, 0);
}

static void RGB565__SWM34SVE_PIN100_A001(void)
{
    /* 针对SWM34SVET6_Demo板上使用RGB565接口时多余IO未接地, 故程序中强制拉低, 用户也可做其他用途 */
    /* R- 8 bit : [ 0 ~ 7 ] */
    GPIO_Init(GPIOC, PIN4, 1, 0, 0, 0);
    GPIO_Init(GPIOC, PIN5, 1, 0, 0, 0);
    GPIO_Init(GPIOC, PIN8, 1, 0, 0, 0);
    GPIO_AtomicClrBit(GPIOC, PIN4);
    GPIO_AtomicClrBit(GPIOC, PIN5);
    GPIO_AtomicClrBit(GPIOC, PIN8);
    /* R- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
    PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
    PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
    PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
    PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
    /* G- 8 bit : [ 0 ~ 7 ] */
    GPIO_Init(GPIOA, PIN12, 1, 0, 0, 0);
    GPIO_Init(GPIOA, PIN13, 1, 0, 0, 0);
    GPIO_AtomicClrBit(GPIOA, PIN12);
    GPIO_AtomicClrBit(GPIOA, PIN13);
    /* G- 6 bit : [ 2 ~ 7 ] */
    PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
    PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
    PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
    PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
    PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
    PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
    /* B- 8 bit : [ 0 ~ 7 ] */
    GPIO_Init(GPIOB, PIN1, 1, 0, 0, 0);
    GPIO_Init(GPIOB, PIN11, 1, 0, 0, 0);
    GPIO_Init(GPIOB, PIN13, 1, 0, 0, 0);
    GPIO_AtomicClrBit(GPIOB, PIN1);
    GPIO_AtomicClrBit(GPIOB, PIN11);
    GPIO_AtomicClrBit(GPIOB, PIN13);
    /* B- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
    PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
    PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
    PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
    PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);
    /* CLK / VS / HS / DE */
    PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
    PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);
    PORT_Init(PORTB, PIN3, PORTB_PIN3_LCD_HSYNC, 0);
    PORT_Init(PORTB, PIN4, PORTB_PIN4_LCD_DEN, 0);
}

static void RGB888__SWM34SVE_PIN100_A001(void)
{
    /* R- 8 bit : [ 0 ~ 7 ] */
    PORT_Init(PORTC, PIN4, PORTC_PIN4_LCD_R0, 0);
    PORT_Init(PORTC, PIN5, PORTC_PIN5_LCD_R1, 0);
    PORT_Init(PORTC, PIN8, PORTC_PIN8_LCD_R2, 0);
    PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
    PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
    PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
    PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
    PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
    /* G- 8 bit : [ 0 ~ 7 ] */
    PORT_Init(PORTA, PIN12, PORTA_PIN12_LCD_G0, 0);
    PORT_Init(PORTA, PIN13, PORTA_PIN13_LCD_G1, 0);
    PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
    PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
    PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
    PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
    PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
    PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
    /* B- 8 bit : [ 0 ~ 7 ] */
    PORT_Init(PORTB, PIN1, PORTB_PIN1_LCD_B0, 0);
    PORT_Init(PORTB, PIN11, PORTB_PIN11_LCD_B1, 0);
    PORT_Init(PORTB, PIN13, PORTB_PIN13_LCD_B2, 0);
    PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
    PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
    PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
    PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
    PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);
    /* CLK / VS / HS / DE */
    PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
    PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);
    PORT_Init(PORTB, PIN3, PORTB_PIN3_LCD_HSYNC, 0);
    PORT_Init(PORTB, PIN4, PORTB_PIN4_LCD_DEN, 0);
}

static void RGB565__SWM34SVE_PIN100_A002(void)
{
    /* 针对SWM34SVET6_Demo板上使用RGB565接口时多余IO未接地, 故程序中强制拉低, 用户也可做其他用途 */
    /* R- 8 bit : [ 0 ~ 7 ] */
    GPIO_Init(GPIOC, PIN4, 1, 0, 0, 0);
    GPIO_Init(GPIOC, PIN5, 1, 0, 0, 0);
    GPIO_Init(GPIOC, PIN8, 1, 0, 0, 0);
    GPIO_AtomicClrBit(GPIOC, PIN4);
    GPIO_AtomicClrBit(GPIOC, PIN5);
    GPIO_AtomicClrBit(GPIOC, PIN8);
    /* R- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
    PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
    PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
    PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
    PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
    /* G- 8 bit : [ 0 ~ 7 ] */
    GPIO_Init(GPIOA, PIN12, 1, 0, 0, 0);
    GPIO_Init(GPIOA, PIN13, 1, 0, 0, 0);
    GPIO_AtomicClrBit(GPIOA, PIN12);
    GPIO_AtomicClrBit(GPIOA, PIN13);
    /* G- 6 bit : [ 2 ~ 7 ] */
    PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
    PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
    PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
    PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
    PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
    PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
    /* B- 8 bit : [ 0 ~ 7 ] */
    GPIO_Init(GPIOB, PIN1, 1, 0, 0, 0);
    GPIO_Init(GPIOB, PIN11, 1, 0, 0, 0);
    GPIO_Init(GPIOB, PIN13, 1, 0, 0, 0);
    GPIO_AtomicClrBit(GPIOB, PIN1);
    GPIO_AtomicClrBit(GPIOB, PIN11);
    GPIO_AtomicClrBit(GPIOB, PIN13);
    /* B- 5 bit : [ 3 ~ 7 ] */
    PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
    PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
    PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
    PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
    PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);
    /* CLK / VS / HS / DE */
    PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
    PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);
    PORT_Init(PORTM, PIN8, PORTM_PIN8_LCD_HSYNC, 0);
    PORT_Init(PORTM, PIN11, PORTM_PIN11_LCD_DEN, 0);
}

static void RGB888__SWM34SVE_PIN100_A002(void)
{
    /* R- 8 bit : [ 0 ~ 7 ] */
    PORT_Init(PORTC, PIN4, PORTC_PIN4_LCD_R0, 0);
    PORT_Init(PORTC, PIN5, PORTC_PIN5_LCD_R1, 0);
    PORT_Init(PORTC, PIN8, PORTC_PIN8_LCD_R2, 0);
    PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
    PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
    PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
    PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
    PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
    /* G- 8 bit : [ 0 ~ 7 ] */
    PORT_Init(PORTA, PIN12, PORTA_PIN12_LCD_G0, 0);
    PORT_Init(PORTA, PIN13, PORTA_PIN13_LCD_G1, 0);
    PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
    PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
    PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
    PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
    PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
    PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
    /* B- 8 bit : [ 0 ~ 7 ] */
    PORT_Init(PORTB, PIN1, PORTB_PIN1_LCD_B0, 0);
    PORT_Init(PORTB, PIN11, PORTB_PIN11_LCD_B1, 0);
    PORT_Init(PORTB, PIN13, PORTB_PIN13_LCD_B2, 0);
    PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
    PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
    PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
    PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
    PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);
    /* CLK / VS / HS / DE */
    PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
    PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);
    PORT_Init(PORTM, PIN8, PORTM_PIN8_LCD_HSYNC, 0);
    PORT_Init(PORTM, PIN11, PORTM_PIN11_LCD_DEN, 0);
}
